﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using ObjectTransposeApi;
using System.Collections;

namespace ObjectTransposeApiSystemTest.TestFixture
{
    [TestFixture]
    public class ToValueBooleanTestFixture
    {
        public class SingleStructure
        {
            public bool Value { get; set; }
        }

        public class ChildStructure
        {
            public bool ValueOne { get; set; }
            public bool ValueTwo { get; set; }
            public bool ValueThree { get; set; }
        }

        public class ParentStructure
        {
            public ChildStructure Value { get; set; }
        }
        
        [Test]
        public void TrueTest()
        {
            var sourceOne = new
            {
                Value = true
            };

            List<object> sources = new List<object>();

            sources.Add(sourceOne);

            SingleStructure singleStructure = ObjectToValue.Copy<SingleStructure>(sources);

            // make sure the field was set
            Assert.IsTrue(singleStructure.Value);
        }

        [Test]
        public void FalseTest()
        {
            var sourceOne = new
            {
                Value = false
            };

            List<object> sources = new List<object>();

            sources.Add(sourceOne);

            SingleStructure singleStructure = ObjectToValue.Copy<SingleStructure>(sources);

            // make sure the field was set
            Assert.IsFalse(singleStructure.Value);
        }

        [Test]
        public void MatchTest()
        {
            var sourceOne = new
            {
                Value = "test"
            };

            List<object> sources = new List<object>();

            sources.Add(sourceOne);

            SingleStructure singleStructure = ObjectToValue.Copy<SingleStructure>(sources);

            // make sure the field was set
            Assert.IsTrue(singleStructure.Value);
        }

        [Test]
        public void NoMatchTest()
        {
            var sourceOne = new
            {
                ValueOne = "test"
            };

            List<object> sources = new List<object>();

            sources.Add(sourceOne);

            SingleStructure singleStructure = ObjectToValue.Copy<SingleStructure>(sources);

            // make sure the field was set
            Assert.IsFalse(singleStructure.Value);
        }
        
        [Test]
        public void ParentTest()
        {
            List<object> values = new List<object>();

            // add values
            values.Add(new { ValueOne = string.Empty });
            values.Add(new { ValueTwo = string.Empty });

            var sources = new
            {
                Value = values
            };

            ParentStructure parentStructure = ObjectToValue.Copy<ParentStructure>(sources);

            // make sure the field was set
            Assert.IsTrue(parentStructure.Value.ValueOne);
            Assert.IsTrue(parentStructure.Value.ValueTwo);
            Assert.IsFalse(parentStructure.Value.ValueThree);
        }
    }
}
